<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="寻访顾问">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入寻访顾问"
          clearable
        />
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker
          v-model="queryParams.startEndTime"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          :clearable="false"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getListData"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="寻访顾问" align="center" prop="userName" />
      <el-table-column label="录入人数" align="center" prop="stotal" />
      <el-table-column label="寻访中" align="center" prop="sone" />
      <el-table-column label="已约面" align="center" prop="stwo" />
      <el-table-column label="约面率" align="center">
        <template slot-scope="scope">
          {{ dataN(scope.row.stwo, scope.row.stotal) }}
        </template>
      </el-table-column>
      <el-table-column label="到面" align="center" prop="sthree" />
      <el-table-column label="到面率" align="center">
        <template slot-scope="scope">
          {{ dataN(scope.row.sthree, scope.row.stotal) }}
        </template>
      </el-table-column>
      <el-table-column label="offer" align="center" prop="sfour" />
      <el-table-column label="offer率" align="center">
        <template slot-scope="scope">
          {{ dataN(scope.row.sfour, scope.row.stotal) }}
        </template>
      </el-table-column>
      <el-table-column label="入职" align="center" prop="ssix" />
      <el-table-column label="入职率" align="center">
        <template slot-scope="scope">
          {{ dataN(scope.row.ssix, scope.row.stotal) }}
        </template>
      </el-table-column>
      <el-table-column label="返费个数" align="center" prop="backNum" />
    </el-table>
  </div>
</template>

<script>
import { listData } from "@/api/system/yg";
import dayjs from "dayjs";
export default {
  name: "Data",
  data() {
    return {
      loading: true,
      queryParams: {
        userName: null,
        startEndTime: [],
      },
      dataList: [],
    };
  },
  created() {
    const startOfDay = dayjs().startOf("day").format("YYYY-MM-DD HH:mm:ss");
    const endOfDay = dayjs().endOf("day").format("YYYY-MM-DD HH:mm:ss");
    this.queryParams.startTime = startOfDay;
    this.queryParams.endTime = endOfDay;
    this.queryParams.startEndTime = [startOfDay, endOfDay];
    this.getListData();
  },
  methods: {
    getListData() {
      this.loading = true;
      this.queryParams.startTime = this.queryParams.startEndTime[0];
      this.queryParams.endTime = this.queryParams.startEndTime[1];
      listData({
        ...this.queryParams,
      }).then((res) => {
        this.dataList = res.data;
        this.loading = false;
      });
    },
    dataN(v1, v2) {
      console.log(v1, v2);
      if (v1 == 0 || v2 == 0) {
        return "0%";
      }
      let value = v1 / v2; // 0.333333...
      let v = Math.floor(value * 1000) / 10 + "%";
      return v;
    },
  },
};
</script>
<style scope>
.el-picker-panel__footer .el-picker-panel__link-btn.el-button--text {
  display: none;
}
</style>
